#include "sensor.h"
#include <QRandomGenerator>
Sensor::Sensor()
{

}

float Sensor::GenAnalogData()
{
    QRandomGenerator* rand = new QRandomGenerator();
    float analogdata = rand->generateDouble() * 16 + 4;
    return analogdata;
}

QByteArray Sensor::GenDigData()
{
    QRandomGenerator* rand = new QRandomGenerator();
    float digdata = rand->generateDouble();
    digdata *= QRandomGenerator::global()->generateDouble() * 10;
    QByteArray res;
    QByteArray qbyte = FloatToByte(digdata);
    res.append(qbyte);
    return res;
}

QByteArray Sensor::FloatToByte(float DigData)
{
    int length = sizeof(DigData);
    QByteArray array;
    array.resize(length);
    memcpy(array.data(),&DigData,length);
    return array;
}
